// https://xue.kaikeba.com/interactive-course/12113
// 游戏分组
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define maxn 1000000 + 10
int p[maxn];

int find(int x) {
    if (p[x] != x) {
        return p[x] = find(p[x]);
    }
    return p[x];
}

void merge(int x, int y) {
    int fx = find(x);
    int fy = find(y);
    p[fx] = fy;
    return ;
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) {
        p[i] = i;
    }
    for (int i = 0; i < m; i++) {
        int x, y;
        scanf("%d%d", &x, &y) ;
        merge(x, y);
    }
    int ans =0;
    for (int i = 0; i < n; i++) {
        ans += (p[i] == i);
    }
    printf("%d\n", ans);
    return 0;
}